Typical HAL IRDA use cases for migration ¶
This section provides information about typical HAL IRDA use cases for migration.
Important
In HAL2, the IRDA driver is removed, and IRDA functionalities are integrated within the HAL UART driver.
Note
The main difference between HAL1 and HAL2 in transmit and receive functions (polling, interrupt, or DMA) is how the buffer size is specified. HAL1 uses Size to count data elements (u8 or u16), while HAL2 uses Size_byte to specify the size in bytes, providing more precise control.
Use case: IRDA communication in polling mode ¶
This use case shows how to transmit or receive IRDA data in polling mode. In HAL2, IRDA support is handled via the HAL UART driver.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
#define DATA_TO_SEND_SIZE 256
#define DATA_TO_RECEIVE_SIZE DATA_TO_SEND_SIZE
uint8_t aTxBuffer[] = " **** IRDA Communication **** ";
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];
IRDA_HandleTypeDef hirda;
HAL_IRDA_Init(&hirda);
(void)HAL_IRDA_Receive(&hirda, aRxBuffer, DATA_TO_RECEIVE_SIZE, 100);
(void)HAL_IRDA_Transmit(&hirda, aTxBuffer, DATA_TO_SEND_SIZE, 100);
|
#define DATA_TO_SEND_SIZE 256
#define DATA_TO_RECEIVE_SIZE DATA_TO_SEND_SIZE
uint8_t aTxBuffer[] = " **** IRDA Communication **** ";
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];
hal_uart_handle_t huart;
hal_uart_irda_config_t uart_irda_config;
HAL_UART_Init(&huart, HAL_UART4);
/* Configure IRDA mode on the UART instance */
HAL_UART_IRDA_SetConfig(&huart, &uart_irda_config);
(void)HAL_UART_Receive(&huart, aRxBuffer, DATA_TO_RECEIVE_SIZE, 100);
(void)HAL_UART_Transmit(&huart, aTxBuffer, DATA_TO_SEND_SIZE, 100);
|
Key changes ¶
In HAL2, the standalone IRDA driver is removed; use the HAL UART driver with IRDA configuration.
API names are updated from HAL_IRDA_* to HAL_UART_*.
Use case: IRDA receive in interrupt mode ¶
This use case shows how to receive IRDA data in interrupt mode. In HAL2, IRDA support is handled via the HAL UART driver.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
#define DATA_TO_RECEIVE_SIZE 256
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];
IRDA_HandleTypeDef hirda;
/* Optional: register receive-complete callback */
HAL_IRDA_RegisterCallback(&hirda, HAL_IRDA_RX_CB_ID, IRDA_RxCpltCallback);
/* Start receive in interrupt mode */
(void)HAL_IRDA_Receive_IT(&hirda, aRxBuffer, DATA_TO_RECEIVE_SIZE);
|
#define DATA_TO_RECEIVE_SIZE 256
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];
hal_uart_handle_t huart;
/* Optional: register receive-complete callback */
HAL_UART_RegisterRxCpltCallback(&huart, UART_RxCpltCallback);
/* Start receive in interrupt mode */
(void)HAL_UART_Receive_IT(&huart, aRxBuffer, DATA_TO_RECEIVE_SIZE);
|
Key changes ¶
HAL2 uses the UART driver (HAL_UART_Receive_IT() + HAL_UART_IRQHandler()) instead of IRDA-specific APIs.
Use case: IRDA transmit in interrupt mode ¶
This use case shows how to transmit IRDA data in interrupt mode. In HAL2, IRDA support is handled via the HAL UART driver.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
#define DATA_TO_SEND_SIZE 256
uint8_t aTxBuffer[DATA_TO_SEND_SIZE] = " **** IRDA Communication **** ";
IRDA_HandleTypeDef hirda;
/* Optional: register transmit-complete callback */
HAL_IRDA_RegisterCallback(&hirda, HAL_IRDA_TX_CB_ID, IRDA_TxCpltCallback);
/* Start transmit in interrupt mode */
(void)HAL_IRDA_Transmit_IT(&hirda, aTxBuffer, DATA_TO_SEND_SIZE);
|
#define DATA_TO_SEND_SIZE 256
uint8_t aTxBuffer[DATA_TO_SEND_SIZE] = " **** IRDA Communication **** ";
hal_uart_handle_t huart;
/* Optional: register transmit-complete callback */
HAL_UART_RegisterTxCpltCallback(&huart, UART_TxCpltCallback);
/* Start transmit in interrupt mode */
(void)HAL_UART_Transmit_IT(&huart, aTxBuffer, DATA_TO_SEND_SIZE);
|
Key changes ¶
HAL2 uses the UART driver (HAL_UART_Transmit_IT() + HAL_UART_IRQHandler()) instead of IRDA-specific APIs.
Use case: IRDA receive in DMA mode ¶
This use case shows how to receive IRDA data in DMA mode. In HAL2, IRDA support is handled via the HAL UART driver.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
#define DATA_TO_RECEIVE_SIZE 255
IRDA_HandleTypeDef hirda;
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];
/* Optional: register receive-complete callback */
HAL_IRDA_RegisterCallback(&hirda, HAL_IRDA_RX_CB_ID, IRDA_RxCpltCallback);
/* Start receive in DMA mode */
(void)HAL_IRDA_Receive_DMA(&hirda, aRxBuffer, DATA_TO_RECEIVE_SIZE);
|
#define DATA_TO_RECEIVE_SIZE 255
hal_uart_handle_t huart;
uint8_t aRxBuffer[DATA_TO_RECEIVE_SIZE];
/* Optional: register receive-complete callback */
HAL_USART_RegisterRxCpltCallback(&huart, UART_RxCpltCallback);
/* Start receive in DMA mode */
(void)HAL_UART_Receive_DMA(&huart, aRxBuffer, DATA_TO_RECEIVE_SIZE);
|
Key changes ¶
HAL2 migrates from HAL_IRDA_Receive_DMA() to HAL_UART_Receive_DMA().
HAL2 DMA start helper naming differs (HAL_DMA_StartPeriphXfer_IT_Opt() versus HAL_DMA_Start_IT()).
Use case: IRDA transmit in DMA mode ¶
This use case shows how to transmit IRDA data in DMA mode. In HAL2, IRDA support is handled via the HAL UART driver.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
#define DATA_TO_SEND_SIZE 255
IRDA_HandleTypeDef hirda;
uint8_t aTxBuffer[DATA_TO_SEND_SIZE] = " **** IRDA Communication **** ";
/* Optional: register transmit-complete callback */
HAL_IRDA_RegisterCallback(&hirda, HAL_IRDA_TX_CB_ID, IRDA_TxCpltCallback);
/* Start transmit in DMA mode */
(void)HAL_IRDA_Transmit_DMA(&hirda, aTxBuffer, DATA_TO_SEND_SIZE);
|
#define DATA_TO_SEND_SIZE 255
hal_uart_handle_t huart;
uint8_t aTxBuffer[DATA_TO_SEND_SIZE] = " **** IRDA Communication **** ";
/* Optional: register transmit-complete callback */
HAL_UART_RegisterTxCpltCallback(&huart, UART_TxCpltCallback);
/* Start transmit in DMA mode */
(void)HAL_UART_Transmit_DMA(&huart, aTxBuffer, DATA_TO_SEND_SIZE);
|
Key changes ¶
HAL2 migrates from HAL_IRDA_Transmit_DMA() to HAL_UART_Transmit_DMA().
DMA completion still triggers a TX complete interrupt path, but HAL2 uses HAL_UART_IRQHandler().
Completion callback naming/parameters differ in HAL2 (byte count instead of element count).









